package org.wicket.jbpm.task.panel;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.jbpm.graph.exe.ProcessInstance;
import org.wicket.jbpm.engine.spring.JbpmLogEngine;
import org.wicket.jbpm.engine.workflow.pages.JbpmProcessTaskPage;
import org.wicket.jbpm.utils.DateFormatter;

/**
 * @author Emmanuel Nollase - emanux
 * created: Jun 4, 2009 - 2:53:49 PM
 */
public class CloseProcessInstancePanel extends Panel {

	@SpringBean private JbpmLogEngine jbpmLogEngine;
	/**
	 * @param id
	 */
	public CloseProcessInstancePanel(String id) {
		super(id);
		
		final ListView processes = new ListView("jbpmprocess",jbpmLogEngine.findAllCloseProcessInstance()){
			@Override
			protected void populateItem(ListItem item) {
				final ProcessInstance inst = (ProcessInstance) item.getModelObject();
				final Link prlink = new Link("prlink", item.getModel()){
					@Override
					public void onClick() {
						setResponsePage(new JbpmProcessTaskPage((ProcessInstance)this.getModelObject()));
					}
				};
				prlink.add( new Label("key", String.valueOf(inst.getId())) );
				item.add(prlink);
				item.add(new Label("start", DateFormatter.format(inst.getStart())  ));
				item.add(new Label("end", DateFormatter.format(inst.getEnd())  ));
				item.add(new Label("ended", String.valueOf(inst.hasEnded()) ));
			} 
		};
		
		add(processes);
	}

	
}

